package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

/**
 * 输出当前Test5所在的不中的类是否被注解@AutoRunClass标注了?
 * 输出格式:
 * 类名:被标注了|没有被备注
 * 如:
 * Person:被标注了
 * Test5:没有被标注
 */
public class Test5 {
    public static void main(String[] args) throws Exception {
        File file = new File(
                Test5.class.getResource(".").toURI()
        );
        System.out.println(file);
        File[] subs = file.listFiles(f -> f.getName().endsWith(".class"));
        for (File sub : subs) {
            String fileName = sub.getName();
            String className = fileName.substring(0, fileName.indexOf("."));
            String paskName = Test3.class.getPackage().getName();
            String a = paskName + "." + className;
            Class cls = Class.forName(a);
            if (cls.isAnnotationPresent(AutoRunClass.class)){
                System.out.println(className+":被标注了");
            }else {
                System.out.println(className+"没有被标注");
            }
        }
    }
}
